﻿#region 信息

// Copyright©2014 Rex Rao all rights reserved.
// File name : SoMcCoffee\Sohobloo.SoMcCoffee\ServiceBase.cs
// Author : Sohobloo
// Create time : 2014/01/24 17:09
// Update time : 2014/02/08 10:44

#endregion

#region 引用

using System;
using System.ComponentModel.Composition;
using Sohobloo.SoCommon;
using Sohobloo.SoCommon.Log;
using Sohobloo.SoMcCoffee.Data;

#endregion

namespace Sohobloo.SoMcCoffee.Service
{
    public abstract class ServiceBase : ILoggable
    {
        /// <summary>
        ///     获取或设置 工作单元对象，用于处理同步业务的事务操作
        /// </summary>
        [Import]
        protected IUnitOfWork UnitOfWork { get; set; }

        public ILogger Logger { get; set; }

        protected OperationResult Commit()
        {
            int result;
            try
            {
                result = UnitOfWork.Commit();
            }
            catch(Exception ex)
            {
                this.LogError(ex);
                return new OperationResult(OperationResultType.Error);
            }
            if(result == 0)
            {
                return new OperationResult(OperationResultType.NoChange);
            }

            return new OperationResult(OperationResultType.Success);
        }
    }
}